package com.test.daily.leetcode.y2021.m12.day1204;

/**
 * @descriptions: canConstruct
 * @author: Tom
 * @date: 2021/12/4 上午 09:41
 * @version: 1.0
 */
public class Code01_CanConstruct {

    public static void main(String[] args) {
        Code01_CanConstruct ccc = new Code01_CanConstruct();
        String ransomNote = "aa", magazine = "aab";
        System.out.println(ccc.canConstruct(ransomNote, magazine));
    }

    public boolean canConstruct(String ransomNote, String magazine) {
            int[] magazineCount = new int[26];
        for(int i = 0; i < magazine.length(); i++){
            char ch = magazine.charAt(i);
            magazineCount[(ch - 'a')]++;
        }
        for(int i = 0; i < ransomNote.length(); i++){
            magazineCount[(ransomNote.charAt(i) - 'a')]--;
            if(magazineCount[(ransomNote.charAt(i) - 'a')] < 0){
                return false;
            }
        }
        return true;
    }
}
